<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var arr = [1, 2, 3, 4, 5];
      var obj = {
        name: "hyt",
        age: 18,
        [Symbol.iterator]() {
          const values = Object.values(this);
          let i = 0;
          return {
            next() {
              if (i < values.length) {
                return { value: values[i++], done: false };
              }
              return { done: true };
            },
          };
        },
      };

      // 遍历数组
      for (var item of arr) {
        console.log(item);
      }

      // 遍历对象
      for (var value of obj) {
        console.log(value);
      }
    </script>
  </body>
</html>
